import java.util.HashMap;
import java.util.Map;

public class a8 {
    public static int lengthOfLongestSubstring(String s) {
        char[] charArray = s.toCharArray();
        int left = 0;
        int right = 0;
        int max = 0;
        int count = 0;
        Map<Character, Character> map = new HashMap<>();
        while (right < charArray.length) {
            if (!map.containsKey(charArray[right])) {
                map.put(charArray[right], charArray[right]);
                right++;
                count++;
                max = Math.max(max, count);
            } else {
                while (map.containsKey(charArray[right])) {
                    map.remove(charArray[left]);
                    left++;
                    count--;
                }
                map.put(charArray[right], charArray[right]);
                count++;
                right++;
            }


        }
        return max;
    }

    public static void main(String[] args) {
        String s = "pwwkew";
        System.out.println(lengthOfLongestSubstring(s));
    }
}
